Array.prototype.sort = function(reverse) {
	reverse = reverse?true:false;
	var tmp;
	for(var i=0; i<this.length-1; i++) {
		for(var j=i+1; j<this.length; j++) {
			var condition = reverse ? this[i]<this[j] : this[i]>this[j];
			if(condition) {
				tmp = this[i];
				this[i] = this[j];
				this[j] = tmp;
			}
		}
	}
	
	return this;
}
Array.prototype.sum = function() {
	var ret = 0;
	for(var i=0; i<this.length; i++) {
		ret += this[i];
	}
	return ret;
}
Array.prototype.sum2 = function(num) {
	var tmp = Array();
	ret = 0;
	for(var i=0; i<this.length; i++) {
		val = parseInt(this[i]); val = val>0 ? val : 0;
		tmp[val] = typeof(tmp[val])=="undefined" ? 0 : tmp[val];
		tmp[val] = tmp[val]+1;
	}
	if(parseInt(num)>0) {
		var it = 0;
		for(x in tmp) {
			if(tmp[x]>=num && x>it) {
				it = x;
			}
		}
		ret = it*num;
	}else{
		ret = tmp;
	}
	return ret;
}
Array.prototype.implode = function(glue) {
	var ret = "";
	for(var i=0; i<this.length; i++) {
		if(i>0) {
			ret += glue;
		}
		ret += this[i];
	}
	return ret;
}